import { useEffect, useState } from "react";
import Testtwo from "./Testtwo"
import { useNavigate } from "react-router"
import { useLocation } from "react-router"
const Testone = () => {
    let navigate = useNavigate();
    let location = useLocation();
    const [msg, setMsg] = useState();

    const changeState = () => {
        navigate("/test", { state: { msg: "HELLO" } })
    }


    useEffect(() => {
        if (location.state?.msg) {
            setMsg(location.state?.msg)
        } else {
            setMsg(null)
        }
    }, [location])


    return (
        <div className="mt-5 ml-5 p-5">
            <button className="btn btn-primary" onClick={changeState}>修改</button>
            {msg ? <Testtwo msg={msg} /> : null}
        </div>
    )
}

export default Testone